import 'dart:async';
import 'package:app_tracking_transparency/app_tracking_transparency.dart';

class SjAppTrackingTransparency {
  late Timer _timer;

  void init() {
    _timer = Timer.periodic(Duration(seconds: 2), (timer) { 
      _checkTrackingStatus();
    });
  }

  void _checkTrackingStatus() async {
    final TrackingStatus status = await AppTrackingTransparency.trackingAuthorizationStatus;
    if (status == TrackingStatus.notDetermined) {
      Future.delayed(Duration(seconds: 2), () async {
        await AppTrackingTransparency.requestTrackingAuthorization();
      });
    } else {
      _timer.cancel();
    }
  }
}